﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace BierdopjeTV.API
{
    class BierdopjeSubs
    {
        //regex pattern for source & codec

        private string Pattern = @".(?<Source>HDTV|PDTV|DVDRIP|DSR|SDTV).(?<Codec>x264|XviD|DivX)?-";
        private string API_KEY = Properties.Settings.Default.APIKEY;

        private int m_EpisodeID = 0;
        private string m_DownloadLink = "";
        private string m_taal = "";
        private string m_FileName = "";
        private string m_Uploader = "";
        private int m_Downloads = 0;
        private string m_Status = "";
        private string m_Codec = "";
        private string m_Source = "";

        public int EpisodeID
        {
            get { return m_EpisodeID; }
            set { m_EpisodeID = value; }
        }

        public string Taal
        {
            get { return m_taal; }
            set { m_taal = value; }
        }
        public string DownloadLink
        {
            get
            {
                return m_DownloadLink;
            }
         
            set
            {
                /*
                 * http://www.bierdopje.com/download/sub/31306/Leverage.S02E10.720p.HDTV.x264-SYS/apikey/XXXXXXXXXXXXXXXXx
                 * moet worden
                 * http://www.bierdopje.com/download/sub/31305/Leverage.S02E10.HDTV.XviD-SYS/userkey/BDUSRDXXXXXXXXXXXXXXXXx
                 */

                m_DownloadLink = value;
                m_DownloadLink = m_DownloadLink.Replace("apikey", "userkey");
                m_DownloadLink = m_DownloadLink.Replace(API_KEY, Database.Database.getSettingValue("UserKey"));                
            }
        }
 
        public string FileName
        {
            get { return m_FileName; }
            set {
                m_FileName = value;

                //Try to parse the source & codec from the file :-)
                Regex r = new Regex(Pattern, RegexOptions.IgnoreCase);
                try 
                {
                    m_Source = r.Match(m_FileName).Result("${Source}");
                }
                catch
                {
                    m_Source = "Onbekend";
                }
                try
                {
                    m_Codec = r.Match(m_FileName).Result("${Codec}");
                }
                catch
                {
                    m_Codec = "Onbekend";
                }
            }
        }

        public string Uploader
        {
            get { return m_Uploader; }
            set { m_Uploader = value; }
        }

        public int Downloads
        {
            get { return m_Downloads; }
            set { m_Downloads = value; }
        }

        public string Status
        {
            get { return m_Status; }
            set { m_Status = value; }
        }

        public string Source
        {
            get { return m_Source; }            
        }

        public string Codec
        {
            get { return m_Codec; }            
        }
    }
}
